package co.com.travelsoft.ati.administrador.interfaz;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.border.TitledBorder;
import javax.swing.*;

public class PanelEliminarUsuario extends JPanel implements ActionListener{
	private JTable jtUsuarios = null;
	private JScrollPane pane = null;
	private JButton botonEliminar = null;
	private JButton botonCancelar = null;
	private TitledBorder tituloPanel;
	private GUIAdministrador framePrincipal = null;
	
	public PanelEliminarUsuario(GUIAdministrador framePpal) throws Exception
	{
		framePrincipal = framePpal;
		iniciarComponentes();
	}
	
	public void iniciarComponentes() throws Exception
	{		
		this.setLayout(null);
		tituloPanel = new TitledBorder("Eliminar Usuarios");
		this.setBorder(BorderFactory.createCompoundBorder(
        		BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder()),
        		BorderFactory.createEmptyBorder(10,10,10,10)));
        this.setBorder(tituloPanel);
        
        cargarUsuarios();        
        pane = new JScrollPane( jtUsuarios );
        this.add(pane);
		pane.setBounds(20, 20, 730, 450);
		
        
		botonEliminar = new JButton("Eliminar Usuario");
		botonEliminar.addActionListener(this);
		this.add(botonEliminar);
		botonEliminar.setBounds(220, 490, 150, 30);
		
		botonCancelar = new JButton("Cancelar");
		botonCancelar.addActionListener(this);
		this.add(botonCancelar);
		botonCancelar.setBounds(390, 490, 150, 30);
	}
	
	private void cargarUsuarios()
	{
		String datosUsuarios[][] = {
				{"1", "usr1", "usr1", "usr1@xxx.xxx"},
				{"2", "usr2", "usr2", "usr2@xxx.xxx"},
				{"3", "usr3", "usr3", "usr3@xxx.xxx"},
				{"4", "usr4", "usr4", "usr4@xxx.xxx"},
						};
			
		String titulosColumnas[] = {"Id", "Login", "Nombre","Email"};
		jtUsuarios = new JTable( datosUsuarios, titulosColumnas );
	}
	
	public void actionPerformed(ActionEvent e)
    {
		Object componente = e.getSource();
        		
        if(componente == botonCancelar)
	  	{
        	framePrincipal.remove(this);        	
        	framePrincipal.repaint();        	
	  	} 
        else if(componente == botonEliminar)
	  	{
        	//int filaSeleccionada = jtUsuarios.getSelectedRow();
        	JOptionPane.showConfirmDialog(this, "Esta seguro que desea eliminar el Usuario: ");
        	//framePrincipal.remove(this);        	
        	//framePrincipal.repaint();        	
	  	} 
        	
    }

}
